package com.rudolfheszele.smsselector.controller;

import com.rudolfheszele.smsselector.view.View;

/**
 * This interface is used to communicate with every kind of controller
 * @author Rudolf Heszele
 * @version 0.2
 */
public interface Controller
{
	/**
	 * This method is used to register a View to the controller
	 * @param view The view which will be handled by the controller
	 * @see View
	 */
	void registerView(View view);
	
	/**
	 * This method is called, when a view is need to be updated
	 * @param view The view which needs to be updated
	 * @see View
	 */
	void updateView(View view);
	
	/**
	 * This method is used to execute GUI related tasks on a View
	 * @param viewId the id of the View the task needs to be executed on
	 * @param task The task to be executed
	 */
	void updateGui(int viewId, Runnable task);
	
	/**
	 * This method returns the View associated with the given id
	 * @param viewId The id of the View
	 * @return The View with the specified id
	 */
	View getView(int viewId);
	
	/**
	 * This method is invoked from the View when a menu is needed
	 * @param view The View where the menu needed on
	 * @param menu The object holding the menu itself
	 * @param clicked The object which the menu was invoked on. Null if it is not a context menu
	 * @return false if a problem occurred true otherwise
	 */
	boolean buildMenu(View view, Object menu, Object clicked);
	
	/**
	 * This method is invoked from a view when a menu is chosen
	 * @param view The view where the choosing happened
	 * @param menu The menu which  was clicked
	 * @return false if a problem occurred true otherwise
	 */
	boolean menuClicked(View view, Object menu);
	
	/**
	 * This method is invoked, when the View's state has to be saved
	 * @param viewId The id of the view to be stored
	 * @param state The object to hold every needed data
	 */
	void saveState(int viewId, Object state);
	
	/**
	 * This method is invoked, when the View's state has to be restored
	 * @param viewId The id of the view to be restored
	 * @param state The object to restore every needed data from
	 */
	void restoreState(int viewId, Object state);
}
